<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="68px">
      <el-form-item label="时间" prop="deviceTime">
        <el-date-picker
          ref="datePicker"
          v-model="dateArea"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          :clearable="false"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="设备码" prop="code">
        <el-input v-model="queryParams.code"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->
    <div class="alarm-list">
      <div class="alarm-item" v-for="(item,key) in alarmList" :key="key">
        <div class="item-main">
          <!-- <div class="item-row">
            <el-tag type="success">已处理</el-tag>
          </div> -->
          <div class="item-row">
            <div class="row-name">{{$t('deviceDetail.deviceAlarm.deviceName')}}：</div>
            <div class="row-value">{{item.deviceName}}</div>
          </div>
          <div class="item-row">
            <div class="row-name">{{$t('deviceDetail.deviceAlarm.target')}}:</div>
            <div class="row-value">{{item.sensorName}}</div>
          </div>
          <div class="item-row">
            <div class="row-name">{{$t('deviceDetail.deviceAlarm.alarmEvent')}}：</div>
            <div class="row-value">{{item.eventName}}</div>
          </div>
          <div class="item-row">
            <div class="row-name">{{$t('deviceDetail.deviceAlarm.alarmContent')}}：</div>
            <div class="row-value">{{item.alarmContent}}</div>
          </div>
          <div class="item-row">
            <div class="row-name">{{$t('deviceDetail.deviceAlarm.dataValue')}}:</div>
            <div class="row-value">{{ item.channelData+'  '+item.unit }}</div>
          </div>
          <div class="item-row">
            <div class="row-name">触发时间：</div>
            <div class="row-value">{{ item.createTime +'~' + item.finishTime }}</div>
          </div>
        </div>
      </div>
      <el-empty v-if="alarmList.length<=0" description="暂无数据" style="margin: 0 auto;"></el-empty>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listEventData } from "@/api/device/device";
export default {
  props:{
    deviceId:'',
  },
  dicts: ['cmd_execute_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备命令执行日志表格数据
      alarmList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        msgId: null,
        msgName: null,
        status: null,
      },
      // 表单参数
      form: {},
      dateArea:[],
    };
  },
  created() {
    if(this.deviceId){
      this.queryParams.deviceId = this.deviceId;
      this.queryParams.sensorId = this.sensorId||'';
      this.getList();
    }
  },
  methods: {
    /** 查询设备命令执行日志列表 */
    getList() {
      this.loading = true;
      listEventData(this.queryParams).then(response => {
        this.alarmList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyId: null,
        msgId: null,
        msgName: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  },
  watch:{
    deviceId(v){
      if(v){
        this.queryParams.deviceId = this.deviceId;
        this.getList();
      }
    }
  }
};
</script>

<style scoped lang="scss" >
.app-container{
  padding: 20px;
}
.alarm-list{
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  margin-top: 10px;
  .alarm-item{
    flex: 0 0 25%;
    max-width: 25%;
    height: 180px;
    padding-left: 3px;
    padding-right: 3px;
    margin-top: 6px;
    .item-main{
      width: 100%;
      height: 100%;
      border: 1px solid #e4e7ed;
      border-radius: 5px;
      padding: 15px;
      font-size: 0.8em;
      color: #222;
      &:hover{
        box-shadow: 0 0 12px rgba(0, 0, 0, .1);
      }
      .item-row{
        display: flex;
        flex-wrap: nowrap;
        margin: 0.6em 0;
        .row-name{
          text-align: right;
        }
        .row-value{
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
